package cli.menu;

import logic.Excel;

public class ExcelPowered extends Function{
	
	private static String[] mainselect = {
		"-= Main menu > Excel Powered =-",
		"[b]: back [u]: undo [r]: redo [h]: home menu",
		"",
		"1. Import",
		"2. Export",
		"3. Load",
//		"4.Back up"
	};
	
	private static State current = State.EXCELPOWERED;
	private static State back = State.MAINMENU;
	
	public static State runMenu() {

		cli.print(mainselect);

		String input = cli.nextLine();

		return processInput(input);
	}

	private static State processInput(String input) {
		State nextState = current;
		
		//if invalid input
		if(input.length() > 1){
			cli.print(INVALIDINPUT);
			return nextState;
		}
		
		char charInput = input.charAt(0);
		
		switch(charInput){
		
		case 'u':
		case 'U':
			tools.undo();
			break;
		case 'r':
		case 'R':
			tools.redo();
			break;
		case 'h':
		case 'H':
			nextState = State.MAINMENU;
		case 'B':
		case 'b':
			nextState = back;
			break;
		case '1':
			//nextState = State.EXCELIMPORT;
			try {
				Excel.add(cli.getApi());
			} catch (Exception e) {
				cli.print(ERROR);
			}
			break;
		case '2':
			//nextState = State.EXCELEXPORT;
			try {
				Excel.export(cli.getApi());
			} catch (Exception e) {
				cli.print(ERROR);
			}
			break;
		case '3':
			//nextState = State.EXCELLOAD;
			try {
				Excel.load(cli.getApi());
			} catch (Exception e) {
				cli.print(ERROR);
			}
			break;
			
			default:
				break;
			
		}
				
		return nextState;
	}	
	
}